<?php
/**
 * common model file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/09/12
 * Time: 10:42
 */

namespace HiCommon\Model;

class OrderMall extends Base
{

    protected $table = 'order_mall';

    protected $guarded = [];

    //public $timestamps = false;

    /**
     * 应该被调整为日期的属性
     *
     * @var array
     */
    protected $dates = [
    ];

    /**
     * 获取图片可用链接
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getImgUrlAttribute($value)
    {
        $arr_data = [
            'src' => $value,
            'full_src' => oss_full_url($value),
        ];
        return $arr_data;
    }

    /**
     * 扩展信息
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getExtendAttribute()
    {
        $s_created_at = $this->created_at;
        $arr_data = [
            'created_at' => ymd_friendly_date($s_created_at),
        ];

        return $arr_data;
    }

    public function shop_name()
    {
        return $this->hasOne(Shop::class, 'id', 'shop_id')->select(['id', 'name', 'phone']);
    }

    /**
     *  关联用户获取用户用户信息
     *  hinq 2019 08 28
     *
     **/
    public function getGoodsInfo()
    {
        return $this->belongsTo(Goods::class, 'goods_id', 'id')
            ->select(['name', 'id', 'title', 'pic_url']);
    }


    /**
     *  关联订单
     *  hinq 2019 08 28
     *
     **/
    /*    public function getOrderMallDetail()
        {
            // return $this->belongsTo(Goods::class,'goods_id','id');
            return $this->belongsTo(OrderMallDetail::class, 'id', 'order_id')->select(['goods_num', 'id', 'goods_price', 'goods_amount','goods_num','goods_integral', 'integral_sum', 'order_id', 'goods_product_id', 'goods_specs_id']);
        }*/

    /**
     *  关联买家
     *  hinq 2019 08 28
     *
     **/
    public function getUserInfo()
    {
        return $this->belongsTo(Users::class, 'user_id', 'id')->select(['id', 'nickname', 'realname', 'email', 'phone', 'sex']);
    }


    /**
     *  关联收货地址
     *  hinq 2019 08 28
     *
     **/
    public function getAddressInfo()
    {
        return $this->belongsTo(Address::class, 'user_address_id', 'id')->select(['phone', 'province', 'city', 'area', 'address', 'id', 'username']);
    }

    /**
     *  关联快递公司
     *  yang 2019 09 27
     *
     **/
    public function getExpressInfo()
    {
        return $this->hasOne(Express::class, 'id', 'xpress_id')->select(['id', 'name', 'type']);
    }

    /**
     * 关联产品表
     */
    public function product_info()
    {
        return $this->hasOne(GoodsProduct::class, 'id', 'goods_product_id')
            ->with(['specs'])
            ->select('id', 'pic', 'goods_specs_id');
    }

}